package com.qimou.iems.service.impl;

import com.qimou.iems.entity.PageArgs;
import com.qimou.iems.entity.PageList;
import com.qimou.iems.entity.QualityRecord;
import com.qimou.iems.mapper.IQualityRecordMapper;
import com.qimou.iems.service.IQualityRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Qimou Xie
 * @date 2018/6/10 0:06.
 **/
@Service
public class QualityRecordServiceImpl implements IQualityRecordService {

    @Resource
    private IQualityRecordMapper qualityRecordMapper;

    @Override
    public void save(QualityRecord record) {
        qualityRecordMapper.insert(record);
    }

    @Override
    public void update(QualityRecord record) {
        qualityRecordMapper.update(record);
    }

    @Override
    public QualityRecord findById(Integer id) {
        return qualityRecordMapper.selectById(id);
    }

    @Override
    public List<QualityRecord> findList(Map<String, Object> map) {
        return qualityRecordMapper.selectList(map);
    }

    @Override
    public PageList<QualityRecord> findPage(PageArgs pageArgs, Map<String, Object> map) {
        List<QualityRecord> qualityRecords = new ArrayList<QualityRecord>();
        int count = qualityRecordMapper.countRecord(map);
        if(count > 0){
            map.put("pageArgs",pageArgs);
            qualityRecords = qualityRecordMapper.selectList(map);
        }
        return new PageList<QualityRecord>(qualityRecords,count);
    }
}
